import PDCItemsInfo from '@/icons/providencraft_item.json'
import useItemCollectPath from './useItemCollectPath'

const PDCItemsMap = new Map(PDCItemsInfo.map((item) => [item.registerName, {
  ...item
}]))

const urlMap = {
  "Item": "items",
  "Block": "blocks",
} as Record<string, string>

const effectedItems = {
  'providencraft:music_disc_around_the_travel': () => {
    return `/wiki/items/music_disc#音乐唱片一人旅行`
  }
} as Record<string, () => string>

/**
 * 获取物品链接
 * @param id 物品 id，请确保物品id以 `providencraft:` 开头
 * @returns 
 */
export default function (id = '') {
  if (id.startsWith('providencraft:')) {
    const type = PDCItemsMap.get(id)?.type
    if (!type) return ''

    const urlType = urlMap[type]
    if (!urlType) return ''

    if (effectedItems[id]) {
      return effectedItems[id]()
    }

    const ItemCollectResult = useItemCollectPath(id)
    if (ItemCollectResult) {
      return ItemCollectResult.path
    }

    return `/wiki/${urlType}/${id.substring(14)}`
  }
  return ''
}